import { LoginForm, Token, User, UserProfile } from '@/types/data'
import { post, get, patch } from '@/utils/request'
enum API {
  login = '/authorizations', //登录
  getCode = '/sms/codes/', //获取验证码
  getProfile = '/user', //获取用户信息
  getUserProfile = '/user/profile', //获取个人信息以便修改
  updateUserPhoto = '/user/photo' //修改个人头像
}
class DataServe {
  static login(data: LoginForm) {
    return post<Token>(API.login, data)
  }
  static getCode(data: string) {
    return get(API.getCode + data)
  }
  static getProfile() {
    return get<User>(API.getProfile)
  }
  static getUserProfile() {
    return get<UserProfile>(API.getUserProfile)
  }
  static updateUserProfile(data: { [key: string]: string }) {
    return patch(API.getUserProfile, data)
  }
  static updateUserPhoto(data: FormData) {
    return patch(API.updateUserPhoto, data)
  }
}

export default DataServe
